<?
layout("/inc/win_layout.html",{title:sysTitle}){
    ?>
<div class="col-lg-4">
	<div class="panel" style="height: 380px; overflow: auto;">
		<div class="panel-body">
			<ul id="tree" class="ztree" style="width:300px"; overflow:auto;"></ul>
		</div>	
	</div>
</div>
<?}?>
<script>
	
/*用做单选  radioType: "all",
				chkStyle: "radio"*/
				
	function getQueryString(name) { 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r != null) return unescape(r[2]); return null; 
	} 
	var winName=getQueryString("winName");
	var recommendClassEns = window.parent.window[winName].getlibraryEnChoose();
	/* var rcs = "";
	if(recommendClassEns != null && recommendClassEns != '' ){
		rcs = recommendClassEns.split(";");
	} */
	/* if(rcs.length>1){
		
	} */
	var classid;
	var classname;
	var screen = window.parent.window[winName].getscreen();
	$(function() {
		/* alert(screen); */
		if(screen == "radio"){
			initTreeRadio();
		}else{
			initTreeMany();
		}
		
	});
	/*多选查询方法*/
	function initTreeMany() {
		$.ajax({
			type : "post",
			data : {
				'anId':recommendClassEns
			},
			url : "./analysisclassListall.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}
	/*单选查询方法*/
	function initTreeRadio() {
		$.ajax({
			type : "post",
			data : {
				'anId':recommendClassEns
			},
			url : "./analysisclassListall.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTreeRadio,
		});
	}
	/*多选树状*/
	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : true,
				nocheckInherit: true,
				chkboxType: {"Y" : "", "N" : ""}
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var nodes = treeObj.getNodes();
		/* for(var i=0;i<data.length;i++){
			if(rcs != ''){
				for ( var j = 0; j < rcs.length; j++) {
					treeObj.checkNode(treeObj.getNodeByParam("nameEn",rcs[j]), true ); 
				}
			}
		} */
	}
	/*单选树状*/
	function drawTreeRadio(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : true,
				nocheckInherit: true,
				chkboxType: {"Y" : "", "N" : ""},
				radioType: "all",
				chkStyle: "radio"
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var nodes = treeObj.getNodes();
		/* for(var i=0;i<data.length;i++){
			if(rcs != ''){
				for ( var j = 0; j < rcs.length; j++) {
					treeObj.checkNode(treeObj.getNodeByParam("nameEn",rcs[j]), true ); 
				}
			}
		} */
	}
	function onClick(e, treeId, treeNode) {
		/* classid = treeNode.id;		
		classname=treeNode.name;   */
	}
	var index = parent.layer.getFrameIndex(window.name);
	function  save(){
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var checkedNode = treeObj.getCheckedNodes(); 
		var nameEn="";
		var nameZh="";
		for(var i=0;i<checkedNode.length;i++){
			if(checkedNode[i].id!=null){
				nameEn += checkedNode[i].nameEn+";";
				nameZh += checkedNode[i].nameZh+";";
			}
		}
		nameEn=nameEn.substring(0,nameEn.length-1);
		nameZh=nameZh.substring(0,nameZh.length-1);
		if(screen == "radio"){
			window.parent.window[winName].$("#analyzeEnName").val(nameEn);
	    	window.parent.window[winName].$("#analyzeZhName").val(nameZh);
		}else{
			window.parent.window[winName].$("#parentClassEnname").val(nameEn);
	    	window.parent.window[winName].$("#parentclassZhname").val(nameZh);
		}
	    parent.layer.close(index);
	    
     }
	
</script>